﻿using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AirlinePilotAcademy_WPF.UI_Administrator.Subject
{
    /// <summary>
    /// Lógica de interacción para SearchSubjectToTeacher.xaml
    /// </summary>
    public partial class SearchSubjectToTeacher : Window
    {
        private SubjectToTeacher selectedItem;

        public SearchSubjectToTeacher()
        {
            InitializeComponent();
            this.DataGrid_Result.ItemsSource = DataAccess.SubjectToTeacherDataAccess.getAllSubjectToTeacher();
        }

        private void SearchBy(object sender, RoutedEventArgs e)
        {

        }

        private void FilterTextChanged(object sender, TextChangedEventArgs e)
        {
            if (String.IsNullOrEmpty(this.TextBox_Filter.Text))
            {
                this.DataGrid_Result.ItemsSource = DataAccess.SubjectToTeacherDataAccess.getAllSubjectToTeacher();
            }
            else
            {
                if (this.RadioButton_SubjectCode.IsChecked == true)
                {
                    this.DataGrid_Result.ItemsSource = DataAccess.SubjectToTeacherDataAccess.getAllSubjectToTeacherByCodeSubject(this.TextBox_Filter.Text);
                }
                if (this.RadioButton_SubjectName.IsChecked == true)
                {
                    this.DataGrid_Result.ItemsSource = DataAccess.SubjectToTeacherDataAccess.getAllSubjectToTeacherByNameSubject(this.TextBox_Filter.Text);
                }

                if (this.RadioButton_TeacherCode.IsChecked == true)
                {
                    this.DataGrid_Result.ItemsSource = DataAccess.SubjectToTeacherDataAccess.getAllSubjectToTeacherByCodeTeacher(this.TextBox_Filter.Text);
                }
                if (this.RadioButton_TeacherCI.IsChecked == true)
                {
                    this.DataGrid_Result.ItemsSource = DataAccess.SubjectToTeacherDataAccess.getAllSubjectToTeacherByCITeacher(this.TextBox_Filter.Text);
                }
            }
        }

        private void SelectedItem(object sender, RoutedEventArgs e)
        {
            if (this.DataGrid_Result.CurrentCell != null)
            {
                selectedItem = (SubjectToTeacher)this.DataGrid_Result.CurrentCell.Item;
                this.DataGrid_Result.SelectedItem = selectedItem;

                this.Button_Modify.IsEnabled = true;
                this.Button_Watch.IsEnabled = true;
            }
            else
            {
                this.Button_Modify.IsEnabled = false;
                this.Button_Watch.IsEnabled = false;
            }
        }

        private void Button_Watch_Click(object sender, RoutedEventArgs e)
        {
            if (this.DataGrid_Result.CurrentCell != null)
            {
                SubjectToTeacherSolution stts = new SubjectToTeacherSolution(selectedItem, "Cerrar");
                stts.ShowDialog();
            }
        }

        private void Button_Modify_Click(object sender, RoutedEventArgs e)
        {
            if (this.DataGrid_Result.CurrentCell != null)
            {
                SubjectToTeacherSolution stts = new SubjectToTeacherSolution(selectedItem);
                stts.ShowDialog();
            }
        }
    }
}
